Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sed expression editing #1542

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sed expression editing #1542

wants to merge 1 commit into from

Conversation

LorenDB
Copy link
Member

@LorenDB LorenDB commented Jul 28, 2023

This reuses the Neochat code to edit your most recent message by sed expressions, but if you reply to one of your messages, it will try to edit that message instead. Also, nheko is smarter and won't blindly apply a sed expression to a message that it won't change.

@LorenDB LorenDB force-pushed the regexEditing branch 2 times, most recently from 2acfe89 to 9d5d813 Compare July 28, 2023 12:29
@LorenDB LorenDB changed the title Regex editing Sed expression editing Jul 28, 2023
if (UserSettings::instance()->sedEditing() && room->edit().isEmpty()) [[unlikely]] {
// The bulk of this logic was shamelessly stolen from Neochat. Thanks to Carl Schwan for
// letting us have this :)
static const QRegularExpression sed("^s/([^/]*)/([^/]*)(/g)?$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means there is no way to escape a / in the regex. Probably fine, but not great. Also I really like that Vim allows you to use any non-alphanumeric character as the separator. So maybe actually go with the /s/ command :)

Comment on lines +488 to +491
if (flags == "/g")
other.replace(regex, replacement);
else
other.replace(other.indexOf(regex), regex.size(), replacement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way the first one will do \1 group replacement, the other one won't.

The proper solution is probably to extract the first match and only do a replace on that, then stitch it back together. The regex.size() also is wrong, since it will behave incorrectly with /s/.*// imo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I understand what you are saying here. Could you elaborate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If you do a replacement with s/.*//, I think your code will just delete 2 characters at the start of the message.
  2. If you do a replacement like s/[abc]*/__\1__/ the first one will replace aaacbbbaaa with __aaacbbbaaa__, the second one will replace it with the literal text __\1__, I think.

This reuses the Neochat code to edit your most recent message by
sed expressions, but if you reply to one of your messages, it will
try to edit that message instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants